<?php

//----------------------------------------------------------
//----------- CHANGEABLE PART ------------------------------
//----------------------------------------------------------

require_once("../../class2.php");
require_once(HEADERF);
		$user_id = USERID;
		$user_name = USERNAME;
require_once("./includes/require_all.php");

$getpart="game=".mysql_real_escape_string($_GET['game'])."&name=".mysql_real_escape_string($_GET['name'])."&page=".mysql_real_escape_string($_GET['page']);

	$_GET['sby']= !isset($_GET['sby']) || $_GET['sby']==0 ? 1 : $_GET['sby'];
	$addEDITtoGET= "&sby=".$_GET['sby'];
	$t_GETS= array("edit","cmpr","type","maxsize");
	FOREACH ($t_GETS as $v) $addEDITtoGET .= isset($_GET[$v]) ? "&".$v."=".$_GET[$v] : "";

$game_show_temp = mysql_fetch_array(mysql_query("select game_show,PRIVATEGAME,id from admin_panel where game_prefix='$CMS_pref'"));
$game_show = $game_show_temp[0]; $game_private= $game_show_temp[1]; $game_private_id= $game_show_temp[2];
if($game_show){

//Common variables
$CMS_file = $_GET['name'];
$CMS_page = get_page();
$CMS_pages= CMS_gamePagerInitiate();

		$per_page_r = $page_rows; //Number of rows to be displayed on 1 page
		$offset = $per_page_r*($CMS_page - 1); //Offset for the pages

//System functions
CMS_dictionarySave();
CMS_activitySave("viewtext.php");

if(USERNAME=="Mnementh") {
	$ttt= mysql_query("SET group_concat_max_len=12560; SELECT GROUP_CONCAT(CONCAT('SELECT english,content FROM ',game_prefix,'_text WHERE content!=english AND english=\"Hi!\"') separator ' UNION ') as needed FROM admin_panel WHERE game_prefix!=''");
	$ttttt= mysql_fetch_assoc($ttt);
	echo $ttttt["needed"];
}

//----------------------------------------------------------
//----------- UNCHANGEABLE PART ----------------------------
//----------------------------------------------------------
//---> Load text arrays for translation
$rowss = mysql_query("SELECT * FROM $text_table WHERE file_name = '".mysql_real_escape_string($CMS_file)."' and content <> '' LIMIT $per_page_r OFFSET $offset");
$arr_textid= array(); $arr_echoid= array(); $arr_translators= array(); $arr_content= array(); $arr_bg= array(); $arr_en= array(); $arr_en_slashed= array(); $key=0;
$cntnt_clr= array(
		 0=>array("&amp;lt;","&amp;gt;","&amp;quot;","&amp;amp;"),
		 1=>array("&lt;",    "&gt;",    "&quot;",    "&amp;"));
$txtarea_clr= array(
		 0=>array("[","]",":"," ","'",".","/","\\","&","#","$"),
		 1=>array("--IC001--","--IC002--","--IC003--","--IC004--","--IC005--","--IC006--","--IC007--","--IC008--","--IC009--","--IC010--","--IC011--"));
while($nextrow = mysql_fetch_array($rowss)){
	$content = trim($nextrow['content']); 
	$content = htmlspecialchars(preg_replace("/\n/", " ", $content));
	$content= str_replace($cntnt_clr[0],$cntnt_clr[1],$content);
	$content2 = trim($nextrow['english']);
	$content2 = preg_replace("/\n/", " ", $content2); 
	$text_id = $nextrow['text_id'];
	$textarea = str_replace($txtarea_clr[0],$txtarea_clr[1],$text_id);
	$translator= $nextrow['translator'];
	$arr_sqlid= $nextrow['id'];
	$arr_textid[$key]= $textarea;
	$arr_echoid[$key]= $text_id;
	$arr_translators[$key]= $translator;
	$arr_content[$key]= $nextrow['content'];
	$arr_bg[$key]= $content;
	$arr_en[$key]= $content2;
	$arr_en_slashed[$key]= $content2;
	$key++;
} unset($key);

//---> Approve/Disapprove status or delete the translation
if(isset($_POST['sbmtchck']) OR $_POST['submit']=="Одобрявай") { 
	$result_all_id = mysql_query("SELECT id FROM $translations_table WHERE page='$CMS_page'");
	while($array_all_id = mysql_fetch_array($result_all_id)){
		$id_translation = array_shift($array_all_id);
		if(isset($_POST["approve_$id_translation"]) OR isset($_POST["r_trans_$id_translation"])){
			if(isset($_POST["approve_$id_translation"])) { $trans = $_POST["trans_$id_translation"]; }
			elseif(isset($_POST["r_trans_$id_translation"])) { $trans = $_POST["r_trans_$id_translation"]; }
			mysql_query("UPDATE $translations_table SET status = 'Одобрен', translation = '".mysql_real_escape_string($trans)."' WHERE id = '$id_translation' AND file_name = '".mysql_real_escape_string($CMS_file)."'");
			$translator= mysql_query("SELECT translator_name FROM $translations_table WHERE id = '$id_translation' LIMIT 1");
			$translator= mysql_fetch_array($translator);
			$translator= $translator['translator_name'];
			
			$translation = explode("\n", $trans); //Dividing user's translation into rows
			$count=0;
			foreach($translation as $appornot){
				if(preg_match('/[А-я]{2}/',$appornot)) $count++;
			}
			$codes = array(); //It will contain codes from user's translation
			foreach($translation as $v){
				$g = explode("=>", $v);
				$codes[] = $g[0];
			}
			foreach($codes as $key => $code){
				$code_repl= 0;
				$t = explode("=>", $translation[$key]);
				if (preg_match("/(_IGcoLLen)/", $code)) { $code_repl= str_replace ("_IGcoLLen", "", $code);};
				if (preg_match("/(IC101: Остави английския текст)/", $t[1])) {  // Сменяме text_id-то на файла, за да бъде считан низът оттук-нататък като преведен
					$t[1]= str_replace ("(IC101: Остави английския текст)", "", $t[1]);
					if ($code_repl!==0) {$code_repl= $code_repl."_IGcoLLen";};
					if ($code_repl===0) {$code_repl= $code."_IGcoLLen";};
				}
				$code= mysql_real_escape_string($code);
				if ($code_repl!==0) {
					$code_repl= mysql_real_escape_string($code_repl);
					mysql_query("UPDATE $text_table SET text_id = replace(text_id, '$code', '$code_repl') WHERE text_id = '$code' AND file_name = '".mysql_real_escape_string($CMS_file)."'");
					$code= $code_repl;
				}
				$s= array_search($code, $arr_echoid); $translator_back= $translator;
				if ($arr_translators[$s]!="original") { $translator=$arr_translators[$s]; }
				mysql_query("UPDATE $text_table SET content = '".mysql_real_escape_string($t[1])."', translator = '".mysql_real_escape_string($translator)."' WHERE text_id = '$code' AND file_name = '".mysql_real_escape_string($CMS_file)."'");
				$translator= $translator_back;
				
				//translating all the same rows
				$x = mysql_query("select * from $text_table where text_id = '$code' and file_name = '".mysql_real_escape_string($CMS_file)."'");
				$y = mysql_fetch_array($x);
				$id = $y['text_id'];
				$eng = $y['english'];
				$bg = $y['content'];
				$tr = $y['translator'];
				$rrr = mysql_query("select * from $text_table where english = binary '".mysql_real_escape_string($eng)."'");
				if(mysql_num_rows($rrr)){
					if(preg_match("/(_IGcoLLen)/", $id)){
						mysql_query("UPDATE $text_table SET text_id = concat(text_id, '_IGcoLLen'), content = '".mysql_real_escape_string($bg)."', translator = '".mysql_real_escape_string($tr)."' WHERE english = binary '".mysql_real_escape_string($eng)."' and translator = 'original'");
						mysql_query("UPDATE $text_table SET text_id = concat(text_id, '_IGcoLLen'), content = '".mysql_real_escape_string($bg)."' WHERE english = binary '".mysql_real_escape_string($eng)."' and translator != 'original'");
					}
					else{
						mysql_query("UPDATE $text_table SET content = '".mysql_real_escape_string($bg)."', translator = '".mysql_real_escape_string($tr)."' WHERE english = binary '".mysql_real_escape_string($eng)."' and translator = 'original'");
						mysql_query("UPDATE $text_table SET content = '".mysql_real_escape_string($bg)."' WHERE english = binary '".mysql_real_escape_string($eng)."' and translator != 'original'");
					}
				}
			}
			CMS_lastApprovedSave($count, $translator);
			$wordsall=mysql_fetch_array(mysql_query("SELECT SUM( LENGTH(english) - LENGTH(REPLACE (english, ' ', ''))+1) FROM $text_table"));
			$wordsdone= mysql_fetch_array(mysql_query("SELECT SUM( LENGTH(english) - LENGTH(REPLACE (english, ' ', ''))+1) FROM $text_table WHERE content!=english OR translator!='original' OR content REGEXP '[а-яА-Я ]{10}'"));
			mysql_query("UPDATE admin_panel SET wordsall='$wordsall[0]', wordsdone='$wordsdone[0]' WHERE game_prefix='$CMS_pref'");
			if ($gamename != "Assassin\'s Creed II") {
				autosysmessage2($count, $translator, $id_translation, $_GET['game'], $game_private,$game_private_id);
			}
			$pendingtranses= mysql_fetch_array(mysql_query("SELECT count(*) FROM $translations_table WHERE `status` = 'В процес на проверка...'"));
			mysql_query("UPDATE `admin_panel` SET `pendingtranses` = '$pendingtranses[0]' WHERE `game_prefix`='$CMS_pref'");
			
			if($_POST['submit']=="Одобрявай" AND !isset($dontcopymytwice)){
				$temp = ''; //Temporary file for containing transformed text for user translation
				$strcount=0;
				foreach ($arr_textid as $k => $w) {
					if($_POST['translation_'.$w] != "" and (preg_match("/([а-яА-Я]{1,}\s?[а-яА-Я]{1,})/u", $_POST['translation_'.$w]) or preg_match("/(_IGcoLLen)/", $w)) and !preg_match("/(<script)/", $_POST['translation_'.$w])){
						$strcount++;
						$tran = punctuation_check($_POST['translation_'.$w]);
						if(preg_match("/\</", $tran)){
							$tran = preg_replace("/</", "&lt;", $tran);
						}
						$temp .= (string)$arr_echoid[$k]."=>".$tran."\n";
					}
				}
				if(strlen($temp) > 0){
					$temp = mysql_real_escape_string($temp);
					$sql_sign_translation = "INSERT INTO $translations_table (translation, original, file_name, translator_id, translator_name, page) VALUES ('".$temp."', '".$temp."', '".mysql_real_escape_string($CMS_file)."', '$user_id', '$user_name', '".mysql_real_escape_string($CMS_page)."')";
					$dontcopymytwice= true;
					mysql_query($sql_sign_translation);
					CMS_statistic1SAVE($strcount);
					autosysmessage1($strcount, $game_private,$game_private_id);
						$pendingtranses= mysql_fetch_array(mysql_query("SELECT count(*) FROM $translations_table WHERE `status` = 'В процес на проверка...'"));
						mysql_query("UPDATE `admin_panel` SET `pendingtranses` = '$pendingtranses[0]' WHERE `game_prefix`='$CMS_pref'");
				}
				unset ($temp, $tran);
			}
			
			header("Location: viewtext.php?game=$CMS_game&name=$CMS_file&page=$CMS_page&go=pending$addEDITtoGET");
		}
		elseif(isset($_POST["change_$id_translation"])){
			$trans = $_POST["trans_$id_translation"];
			mysql_query("UPDATE $translations_table SET translation = '".mysql_real_escape_string($trans)."' WHERE id = '$id_translation' AND file_name = '".mysql_real_escape_string($CMS_file)."'");
			$translator= mysql_query("SELECT translator_name FROM $translations_table WHERE id = '$id_translation' LIMIT 1"); $translator= mysql_fetch_array($translator); $translator= $translator['translator_name'];
			$translation = explode("\n", $trans); $count= count($translation);
			if ($gamename != "Assassin\'s Creed II") {
				autosysmessage3($count, $translator, $id_translation, $_GET['game'], $game_private,$game_private_id);
			}
			header("Location: viewtext.php?game=$CMS_game&name=$CMS_file&page=$CMS_page&go=pending$addEDITtoGET");
		}
		elseif(isset($_POST["disapprove_$id_translation"])){
			$translator= mysql_query("SELECT translator_name FROM $translations_table WHERE id = '$id_translation' LIMIT 1");
			$translator= mysql_fetch_array($translator);
			$translator= $translator['translator_name'];
			mysql_query("UPDATE $translations_table SET status = 'Неодобрен' WHERE id = '$id_translation'");
			if ($gamename != "Assassin\'s Creed II") {
				autosysmessage4($translator, $id_translation, $_GET['game'], $game_private,$game_private_id);
			}
			$pendingtranses= mysql_fetch_array(mysql_query("SELECT count(*) FROM $translations_table WHERE `status` = 'В процес на проверка...'"));
			mysql_query("UPDATE `admin_panel` SET `pendingtranses` = '$pendingtranses[0]' WHERE `game_prefix`='$CMS_pref'");
			header("Location: viewtext.php?game=$CMS_game&name=$CMS_file&page=$CMS_page&go=pending$addEDITtoGET");
		}
		elseif(isset($_POST['delete_'.$id_translation])){
			mysql_query("DELETE FROM $translations_table WHERE id = '$id_translation'");
			$pendingtranses= mysql_fetch_array(mysql_query("SELECT count(*) FROM $translations_table WHERE `status` = 'В процес на проверка...'"));
			mysql_query("UPDATE `admin_panel` SET `pendingtranses` = '$pendingtranses[0]' WHERE `game_prefix`='$CMS_pref'");
			if ($gamename != "Assassin\'s Creed II") {
				autosysmessage5($_GET['game'], $game_private,$game_private_id);
			}
			header("Location: viewtext.php?game=$CMS_game&name=$CMS_file&page=$CMS_page&go=pending$addEDITtoGET");
		}
	}
} else {
	//---> Chat Open
	if(in_array(USERNAME,$adminss) OR in_array(USERNAME,$additionaltoadmins) OR in_array(USERNAME,$trainees)){
		ramka("open","Вътрешен чат");
		include("chats/index.php");
		ramka("close");
		echo "<div style='min-height:25px'></div>";
	}

	ramka("open","Текст на играта за превод");
	//---> Record the posted translation
	if(isset($_POST['submit']) AND $_POST['submit']="Изпрати"){
	$temp = ''; //Temporary file for containing transformed text for user translation
	$strcount=0;
	foreach ($arr_textid as $k => $w) {
		if($_POST['translation_'.$w] != "" and (preg_match("/([а-яА-Я]{1,}\s?[а-яА-Я]{1,})/u", $_POST['translation_'.$w]) or preg_match("/(_IGcoLLen)/", $w)) and !preg_match("/(<script)/", $_POST['translation_'.$w])){
			$strcount++;
			$tran = punctuation_check($_POST['translation_'.$w]);
			if(preg_match("/\</", $tran)){
				$tran = preg_replace("/</", "&lt;", $tran);
			}
			$temp .= (string)$arr_echoid[$k]."=>".$tran."\n";
		}
	}
	if(strlen($temp) > 0){
		$temp = mysql_real_escape_string($temp);
		if(isset($_GET['cmpr'])) $user_name= "SYSTEM BOT";
		$sql_sign_translation = "INSERT INTO $translations_table (translation, original, file_name, translator_id, translator_name, page) VALUES ('".$temp."', '".$temp."', '".mysql_real_escape_string($CMS_file)."', '$user_id', '$user_name', '".mysql_real_escape_string($CMS_page)."')";
		mysql_query($sql_sign_translation);
		CMS_statistic1SAVE($strcount);
		autosysmessage1($strcount, $game_private,$game_private_id);
		$user_name= USERNAME;
			$pendingtranses= mysql_fetch_array(mysql_query("SELECT count(*) FROM $translations_table WHERE `status` = 'В процес на проверка...'"));
			mysql_query("UPDATE `admin_panel` SET `pendingtranses` = '$pendingtranses[0]' WHERE `game_prefix`='$CMS_pref'");
	}
	unset ($temp, $tran);
	}
	//---> Load translated ids for for yellow, green and red markings
	$rowss = mysql_query("SELECT id,translation,translator_name FROM $translations_table WHERE file_name = '".mysql_real_escape_string($CMS_file)."' and page = '".mysql_real_escape_string($CMS_page)."' and status = 'В процес на проверка...'");
	while($nextrow = mysql_fetch_array($rowss)){
		if($nextrow['translation'] != ''){
			$temp = explode("\n", $nextrow['translation']); //Dividing user's translation into rows
			foreach($temp as $k=>$v){
				$part = explode("=>", $v);
				if(!isset($part[1])) {$part[1]="";}
				else $part[1]=str_replace("&#xA","&amp;#xA",$part[1]);
				$arr_transids[] = $part[0];
				$arr_transes[] = $part[1];
				$arr_transons[] = $nextrow['translator_name'];
				$arr_transinputcodes[]=<<<WITING_APPROVAL_TEXTAREA
					<div style='margin-bottom:5px;'><textarea id='r_{$nextrow['id']}{$k}_t' name='r_{$nextrow['id']}{$k}_t' class='expand tbox borderGREY TBOX2' style='width:96%; margin:0px; color:yellow;' onChange='clonecontent("r_{$nextrow['id']}{$k}_t","r_{$nextrow['id']}$k");populateTextArea("UFORM_{$nextrow['id']}","r_{$nextrow['id']}","trans_{$nextrow['id']}");' onKeyUp='clonecontent("r_{$nextrow['id']}{$k}_t","r_{$nextrow['id']}$k");populateTextArea("UFORM_{$nextrow['id']}","r_{$nextrow['id']}","trans_{$nextrow['id']}");'>$part[1]</textarea>
					<div style='float:right; '><span class='button textRED' onClick='clearTextArea("r_{$nextrow['id']}{$k}");populateTextArea("UFORM_{$nextrow['id']}","r_{$nextrow['id']}","trans_{$nextrow['id']}");' style='vertical-align:middle;'>X</span></div></div>
WITING_APPROVAL_TEXTAREA;
				$arr_transsumids[$nextrow['id']]=trim($nextrow['translation']);
			}
		}
	}
	unset ($rowss, $nextrow, $temp, $v, $part);

	require_once("viewtext-topmenu.php");

	$dict= CMS_dictionaryLoad();
	$arr_bg2= CMS_insertDictTooltips($dict, $arr_en);

	$pagehistory= mysql_query("SELECT `user_name` FROM `cms_actusers` WHERE `date` > NOW() - interval 20 minute AND location_present LIKE '%$getpart%' AND user_name!='USERNAME'");
	WHILE($useronpage= mysql_fetch_assoc($pagehistory)){
		$usersonpage[]= "<span class='forumheader' style='background:none;'>$useronpage[user_name]</span>";
	}
	$usersimplode= implode(", ",$usersonpage);
	if(USERNAME!="USERNAME") echo "<div style='padding:0px 5px 0px 5px'><b>На тази страница</b>: $usersimplode</div>";

	if(isset($strcount) AND $strcount>0) {
		echo "<center class='cmsMessage' style='padding-top:4px;'><span class='textRED' style='font-size:24px;'>✉</span> <b style='vertical-align:top;'>Репликите бяха запазени. Благодарим ви! </b></center>"; }	
	CMS_lastApprovedEcho();

	if(USERNAME=="USERNAME") echo "<br>";
	echo "</div><div class='forumheader4'>";

?>
				<div id='enbgwordFOUND'></div>
				<div id='searchFOUND'></div>
<?php
	//---> Show form for acquiring translations
	if($user_rights["ADD"]===1 && USERNAME!='USERNAME'){
			if ($user_rights["APPROVE"]===1) {
				$gamedict= mysql_fetch_array(mysql_query("SELECT count(status) FROM cms_dict WHERE game='$CMS_game' AND status=0"));
				if ($gamedict[0]>0) echo "<div class='forumheader'><b>В игровия речник чакат одобрение думи: </b><a href='dict.php#$CMS_game' class='button'>$gamedict[0]</a></div>";
			}
		$text = ''; //It will contain the untranslated text for the edittext.php
		echo '<form action="" method="post" style="display: inline;">';
		echo "<div onmouseup=\"parseselection()\"><TABLE CELLSPACING='0' CELLPADDING ='4' WIDTH='100%'>";
		$rowcolors= array("green"=>0,"yellow"=>0,"red"=>0);
		foreach ($arr_echoid as $key => $value) {
			$text_id= $value; $content= $arr_bg[$key]; $content2= $arr_en[$key]; $content_slashed= $arr_en_slashed[$key]; $translator= $arr_translators[$key]; $content_tooltiped= $arr_bg2[$key];
			$bg_escaped=str_replace('"', '&quot;', $content); $bg_escaped=str_replace("'", "\'", $bg_escaped); $bg_escaped=str_replace("  ", " ", $bg_escaped); $bg_escaped=addslashes($bg_escaped);
			$textarea= $arr_textid[$key];
			$show_maxsize= isset($_GET["maxsize"]) ? (strlen($content2)<=$_GET["maxsize"] ? true : false) : true;
			$show_type= isset($_GET["type"]) ? $_GET["type"] : 0;
//----------------------------------
			if (isset($_GET['cmpr'])AND in_array(USERNAME,$gods)) {
				if(preg_match("/\|/",$_GET['cmpr'])) {
					$r_bds=explode("|",$_GET['cmpr']);
				} else $r_bds= array($_GET['cmpr']);
				if (isset($recemplate)) unset($recemplate);
				FOREACH($r_bds as $r_bd){
					$r_bd= mysql_real_escape_string($r_bd)."_text";
					$r_srch= mysql_real_escape_string($content2);
					$tempor= mysql_query("SELECT content FROM $r_bd WHERE english='$r_srch' and english!=content");
					WHILE ($a= mysql_fetch_array($tempor)){
					$recemplate[]= $a['content'];
					}
				}
			}
//----------------------------------			
			if ($key%2==1) { $class= "cmsRow1"; } else { $class= "cmsRow2"; }
			$ttxt=""; $ttxt2="";
			if (isset($arr_transids) AND in_array($text_id, $arr_transids)) { 
				foreach($arr_transids as $tk=>$tv) {
					if($tv==$text_id and $arr_transes["$tk"]!="") {
						$ttxt.= "<span class='textYELLOW unselectable'>$arr_transes[$tk]</span><span class='unselectable textWHITE defcursor' style='font-size:10px; margin-top:-5px; margin-left:10px;'>$arr_transons[$tk]</span><br>";
						$ttxt2.= $arr_transinputcodes["$tk"];
					}
				}
			}
			if($user_rights["APPROVE"]===1) $ttxt=$ttxt2;
			if(preg_match("/([а-яА-Я]{1,}\s?[а-яА-Я]{1,})/u", $content) OR preg_match("/(_IGcoLLen){1}/", $text_id)){
				$rowcolors["green"]++;
				$charcount= strlen($arr_bg2[$key]);
				$arr_temp_green[]= $text_id;
	if($show_maxsize&&$show_type<1){
				echo <<<HTML
				<tr style='font-size:14px;' id='row_$textarea'>
				<td style="vertical-align:top;" WIDTH="2%" class='forumheader3 unselectable'>
				<span class='textGREEN' title='Репликата е преведена и одобрена.' style='cursor:help; float:right;'>✔</span>
				</td>
HTML;

		if($user_rights["APPROVE"]===0||(!$_GET["cmpr"]||!$_GET["edit"])) {						
				echo <<<HTML
				<td class="forumheader3"  style="vertical-align:top;" align='left'>
				<span class='unselectable' unselectable="on" oncopy="return false" onpaste="return false" oncut="return false" onclick=toggleBLOC('toggleText_$textarea') style='cursor:pointer;' title='Нов превод'> $content</span>
				<span style="font-size:10px; margin-top:-5px;" class="unselectable textWHITE defcursor"> &nbsp; $translator</span>
				$ttxt<br>
				<div id="toggleText_$textarea" style='display:none;'>
				<span class="textRED">$content_tooltiped</span><br>
				<textarea name="translation_$textarea" id="trans_$textarea" 
							oncopy="return false" onpaste="return false" oncut="return false"
							onkeyup="countTextchars(this, '#chars_$textarea', '$charcount')"
							onfocus="showBLOC('rh_$textarea');countTextchars(this,'#chars_$textarea','$charcount')"
							onblur="hideBLOC('rh_$textarea')"
							style="border-radius: 1px; margin-top:-1px; width: 99%"
							class="expand tbox TBOX2"
HTML;
				if(preg_match("/(_IGcoLLen){1}/", $text_id)) { $content.="(IC101: Остави английския текст)"; }
				if(!isset($addxxx)) $addxxx=""; if(!isset($addxxx2)) $addxxx2="";
				echo <<<HTML
							onclick="autoInsert('trans_$textarea', '$content');"></textarea>
				<div style='margin-top:-5px;display:none;' id='rh_$textarea'>
				<span id="main_$textarea" class="textGREEN" style="font-size:12px;cursor:help;" title="Идентификатор на репликата\nМоже да съдържа важна информация за говорещия, ситуацията и т.н.">[$text_id]</span>  
				<span id='chars_$textarea' style='margin-top:-5px; font-size: 12px; cursor:help;' title='Информативно съотношение на\nпреведения текст спрямо оригинала.\nСпазването му не е задължително.'></span>
				$addxxx $addxxx2</div>
				</div>
HTML;
		} else {
				echo <<<HTML
				<td WIDTH="68%" class="forumheader3" style="vertical-align:top;">
				<span> $content</span><br>
				<span class="textRED" style="font-weight:normal;"> $content_tooltiped</span>
HTML;
				echo <<<HTML
				</td>
				<td WIDTH="30%" class="forumheader3" style="vertical-align:top;">
				<textarea name="translation_$textarea" id="trans_$textarea" 
							onkeyup="countTextchars(this, '#chars_$textarea', '$charcount')"
							onfocus="countTextchars(this, '#chars_$textarea', '$charcount')"
							onblur="toggleSpan('chars_$textarea', '');"
							style="border-radius: 1px; margin-top:-1px; width: 100%"
							class="expand tbox TBOX2"
HTML;
							if(preg_match("/(_IGcoLLen){1}/", $text_id)){
								echo "onclick=\"javascript:autoInsert('trans_$textarea', '$content'+'(IC101: Остави английския текст)');\"></textarea>";}
							else echo "onclick=\"javascript:autoInsert('trans_$textarea', '$content');\"></textarea>";
							echo "<div style='font-size:10px; margin-top:-5px;'><span class='textGREEN'>[$text_id]</span>
								<span id='chars_$textarea' style='margin-top:-5px; cursor:help;' title='Информативно съотношение на\nпреведения текст спрямо оригинала.\nСпазването му не е задължително.'></span>
								<span style='font-size:10px; margin-top:-5px;' class='unselectable textGREY defcursor'> &nbsp; $translator</span></div>";
		}
				echo "</td></tr>";
	}
			}
			else{
				$charcount= strlen($arr_bg[$key]);
				if (isset($arr_transids) AND in_array($text_id, $arr_transids)) { 
					$icon= "✉"; $color= "YELLOW"; $titled="Има чакащ одобрение превод..."; $rowcolors["yellow"]++;
				}
				else {
					$icon= "✘"; $color= "RED"; $titled="Репликата все още не е превеждана."; $rowcolors["red"]++;
				}
				$text .= $text_id."=".$content."\n";
	if($show_maxsize){
				echo <<<HTML
				<tr style='font-size:14px;'>
				<td style="vertical-align:top;" WIDTH="2%" class='forumheader3 unselectable'>
				<span class='text$color' title='$titled' style='cursor:help;'>$icon</span>
				</td>
HTML;
		if($user_rights["APPROVE"]===0||(!$_GET["cmpr"]||!$_GET["edit"])) {						

/*				$ingamecodes="";
				$specialcodes= array(
					"&lt;"=>array("&lt;(.*?)&gt;"),
					"<"=>array("<(.*?)>"),
				//	"%"=>array("%(.*?)%"),
					"["=>array("\[(.*?)]"),
					"{"=>array("{(.*?)}") );
					$specialcodes= array_merge($specialcodes,$specialcodes_add);
				FOREACH($specialcodes as $posthis=>$splitthose){
					if(strpos($content,$posthis)!==false){
						foreach($splitthose as $splitthat){
							$content_temp=str_replace("\"","&quot;",$content);
							preg_match_all("/$splitthat/","$content_temp",$ingamecodestaken);
							$ingamecodes.=implode("",$ingamecodestaken[0]);
							unset($ingamecodestaken);
						}
					}
				}					*/
				
				foreach ($dict as $w) {
					$w= trim($w['word']);
					$preg_apend= $preg_apend."|".ucfirst($w);
					$w{0} = strtolower($w{0});
					$preg_apend.= "|".$w;
				}
				$cnt_srch= array("\\","'"); $cnt_repl= array("\\\\","&amp;apos;");
				preg_match_all("/\\\\[n]{0,1}|[^A-z&]{0,100}((<|&lt;|&amp;lt;)(.*?)(>|&gt;|&amp;gt;)|\((.*?)\)|\[(.*?)\]|\{(.*?)\}|(&amp;|&)(.*?);|%[^ %]{0,100}|[^ ]{0,100}%".$preg_apend.")[^A-z%\(\)\[\]\{\}<>&]{0,100}|[0-9 \.,-:$%]{4,100}|[*\(\)\[\]\{\}<>]{0,100}/",str_ireplace($cnt_srch,$cnt_repl,$content),$ingamecodestaken, PREG_PATTERN_ORDER);
				$ingamecodes=implode("",$ingamecodestaken[0]);
				foreach ($dict as $w) {
					$w1= trim($w['word']);
					$w2= trim($w['translation']); preg_match("/<b>(.*?)<\/b>/", $w2, $w2_t); $w2= $w2_t[1];
					$w1= ucfirst($w1);
					$w2= mb_convert_case($w2, MB_CASE_TITLE, "UTF-8");
					$w1s[]=$w1; $w2s[]=$w2;
					$w1[0]= strtolower($w1[0]);
					$w2= mb_convert_case($w2, MB_CASE_LOWER, "UTF-8");
					$w1s[]=$w1; $w2s[]=$w2;
					$ingamecodes= str_replace($w1s,$w2s,$ingamecodes);
				}
				
				
				echo <<<HTML
				<td class="forumheader3" align="justify" style="vertical-align:top;">
				$content_tooltiped<br>$ttxt
				<textarea name="translation_$textarea" rows="1" id="trans_$textarea" 
							style="border-radius: 1px; margin-top:-1px; margin-bottom:5px; width: 94%"
							class="expand tbox borderGREY TBOX2"
							onkeyup="countTextchars(this, '#chars_$textarea', '$charcount')"
							onfocus="showBLOC('rh_$textarea');countTextchars(this,'#chars_$textarea','$charcount');autoInsert('trans_$textarea','$ingamecodes')"
							onblur="hideBLOC('rh_$textarea')"></textarea>
				<span id="unneeded" class="unselectable"> </span>
HTML;
		} else {
				echo <<<HTML
				<td class="forumheader3" WIDTH="68%" style="vertical-align:top;">
				$content_tooltiped<br>$ttxt
HTML;
				IF (isset($recemplate[0])) {
					FOREACH ($recemplate as $a) { echo "<div class='textWHITE'>$a<div>"; }
					$filler= trim($recemplate[0]);
				} ELSE $filler="";
				echo <<<HTML
				</td>
				<td class="forumheader3" WIDTH="30%" style="vertical-align:top;">
				<textarea name="translation_$textarea" rows="1" id="trans_$textarea" 
							style="border-radius: 1px; margin-top:-1px; margin-bottom:5px; width:82%;"
							class="expand tbox borderGREY TBOX2"
							onkeyup="countTextchars(this, '#chars_$textarea', '$charcount')"
							onfocus="showBLOC('rh_$textarea');countTextchars(this,'#chars_$textarea','$charcount')"
							onblur="hideBLOC('rh_$textarea')">$filler</textarea>
				<span id="unneeded" class="unselectable"> </span>
HTML;
		}
				echo <<<HTML
							<span style='cursor: pointer; vertical-align:top;' 
							alt="Добави" title='Остави на английски' class="unselectable button textWHITE" style="margin-top:-15px;"
HTML;
							if(preg_match("/\"/", $content_slashed)){
								$content_slashed = str_replace('"', '\\"', $content_slashed);
								echo <<<HTML
								onClick='javascript:document.getElementById("trans_$textarea").value = "$content_slashed(IC101: Остави английския текст)";' >
HTML;
							}
							elseif(preg_match("/\'/", $content_slashed)){
								$content_slashed = str_replace("'", "\\'", $content_slashed);
								echo <<<HTML
								onClick="javascript:document.getElementById('trans_$textarea').value = '$content_slashed(IC101: Остави английския текст)';" >
HTML;
							}
							else{
								echo <<<HTML
								onClick="javascript:document.getElementById('trans_$textarea').value = '$content_slashed(IC101: Остави английския текст)';" >
HTML;
							}
							if(!isset($addxxx)) $addxxx=""; if(!isset($addxxx2)) $addxxx2="";
							echo <<<HTML
								EN</span>
				<br><div style='margin-top:-5px;display:none;' id='rh_$textarea'><span id="main_$textarea" class="text$color" style="font-size:12px;cursor:help;" title="Идентификатор на репликата\nМоже да съдържа важна информация за говорещия, ситуацията и т.н.">[$text_id]</span>  <span id='chars_$textarea' style='margin-top:-5px; font-size: 12px; cursor:help;' title='Информативно съотношение на\nпреведения текст спрямо оригинала.\nСпазването му не е задължително.'></span>$addxxx $addxxx2</div></td></tr>
HTML;
	}
			}
		}
			echo '</TABLE></div><br></div><div class="forumheader" style="font-weight:normal;">';
			
			$rc=$rowcolors["red"]; $yc=$rowcolors["yellow"]; $gc=$rowcolors["green"]; 
			if($yc==0 AND $gc==0) { $qcolor= "red"; }
			elseif($rc==0 AND $yc==0) { $qcolor= "green"; }
			elseif(($yc+$gc)<$rc) { $qcolor= "orange"; }
			elseif(($yc+$gc)>$rc) {
				if($rc==0) $qcolor= "green2";
				else $qcolor= "yellow";
			}
			$insert= "$CMS_game??$CMS_file??$CMS_page";

			mysql_query("INSERT INTO cms_overalpages (page, status) VALUES ('".mysql_real_escape_string($insert)."', '$qcolor') ON DUPLICATE KEY UPDATE status='$qcolor'");
			
			echo '<center class="unselectable" style="margin-top:-15px;"><input name="submit" type="submit" value="Изпрати" class="button" id="send-trans">';
			if ($user_rights["APPROVE"]===1 and !isset($_GET['edit'])) { echo " <a href='viewtext.php?game=$CMS_game&name=$CMS_file&page=$CMS_page&edit=true' class='unselectable button textRED' style='font-weight:normal;'>Редакция</a>"; }
			elseif ($user_rights["APPROVE"]===1 and isset($_GET['edit'])) { echo " <a href='viewtext.php?game=$CMS_game&name=$CMS_file&page=$CMS_page' class='unselectable button textRED' style='font-weight:normal;'>Стандартно</a>"; }
			if($user_rights["APPROVE"]===1 and count($arr_transes)>0) { echo ' <input name="submit" type="submit" value="Одобрявай" class="button textGREEN">'; }
			echo '</center>';
			if ($user_rights["APPROVE"]===1) {
				FOREACH($arr_transsumids as $untrans=>$transtext) {	?>
					<textarea name="r_trans_<?=$untrans?>" id="r_trans_<?=$untrans?>" class="expand tbox borderGREY TBOX2" style="width:99%;opacity:0.4;display:none;"><?=$transtext?></textarea>	<?
				}
			}
			echo '</form>';
			echo "<br>";
		
	//---> Alpha-pager (Previous|Present|Next)		
			$p_prev=$CMS_page-1; $p_next=$CMS_page+1;
			if ($CMS_pages>1)
			{
				echo '<center class="unselectable" style="margin-top:-10px;">';
				if ($p_prev>0 AND $p_prev<=$CMS_pages) {
				echo "<a id='prev-page' href='viewtext.php?game=$CMS_game&name=$CMS_file&page=$p_prev$addEDITtoGET' style='font-size:24px; vertical-align:bottom;'>◄</a>";};
				echo "<a class='button textWHITE defcursor' style='font-size:14px;cursor:help;' title='Настояща страница'><b>$CMS_page</b></a>";
				if ($p_next>0 AND $p_next<=$CMS_pages) {
				echo "<a id='next-page' href='viewtext.php?game=$CMS_game&name=$CMS_file&page=$p_next$addEDITtoGET' style='font-size:24px; vertical-align:bottom;'>►</a>";};	
				echo "</center>";
				echo '<br>';
			}
			
	//---> Counting the comments
			$num_notes= mysql_fetch_array (mysql_query("SELECT COUNT(*) FROM cms_notes WHERE game = '".mysql_real_escape_string($CMS_game)."'"));
			$num_notes= $num_notes['0'];

	//---------------------------- SECOND MENU START ------------------------------------
	?>
					<div class="forumheader4">
						<center style='margin-top:-16px;'>
							<table class="forumheader4">
								<tr>
									<td class="cmsMenuDivider defcursor"><<</td>
									<td class="cmsMenuTab cmsMenuTab-back" onclick="javascript: window.location='filestable.php?game=<?=$CMS_game?>&page=<?=$_GET['sby']?>';">НАЗАД</td>
									<td class="cmsMenuDivider defcursor">||</td>
									<td class="cmsMenuTab" onclick="javascript:toggle2('pages001'); toggle3('transes001'); toggle3('comments001');">Страници</td>
									<td class="cmsMenuDivider defcursor">||</td>
									<td class="cmsMenuTab" onclick="javascript:toggle2('transes001'); toggle3('pages001'); toggle3('comments001');">Преводи</td>
									<td class="cmsMenuDivider defcursor">||</td>
									<td class="cmsMenuTab" onclick="javascript:toggle2('comments001'); toggle3('pages001'); toggle3('transes001');">Бележки: <b class="cmsNumNotes textBLACK"> <?=$num_notes?> </b></td>
									<td class="cmsMenuDivider">>></td>
								</tr>
							</table>
						</center>
					<br>
	<?php
	//---------------------------- SECOND MENU END ------------------------------------
	
	//---> Alpha-pager (Page list)
	if(!isset($_GET['go'])) $_GET['go']=""; if(!isset($_POST['editoract'])) $_POST['editoract']="";
	if($_GET['go']!="pending" AND $_POST['editoract'] != "yes") { echo "<div id='pages001' style='display:block'>"; }
	else { echo "<div id='pages001' style='display:none'>"; }
		$all_pages_array = array(); $pages_array = array();
		$pages_status= CMS_gamePagerOverall_Load();
		for($i=1;$i<=$CMS_pages;$i++){ 
			if (!isset($pages_status[$i])) $pages_status[$i]="red";
			if ($i==$CMS_page) { $brdrWHITE = "borderWHITE"; } else $brdrWHITE="";
			$pages_array[] = "button text".strtoupper($pages_status[$i])." $brdrWHITE";
			
		}
		$per = 0;
		if ($CMS_pages>999) {$TDwitdh="35px";$cons=18;} elseif ($CMS_pages>99) {$TDwitdh="25px";$cons=20;} else {$TDwitdh="15px";$cons=25;}; // Набързо скалъпвам широчината и броя на колоните в pager-а, съобразно броя на страниците, за да са с еднаква ширина бутоните в него
		echo "<table style='text-align:center; border-collapse:separate;'><tr>";
		for($i=1;$i<=$CMS_pages;$i++){
			if($per%$cons == 0){
				echo "</tr>";
			}
			if($per%$cons == 0){
				echo "<tr>";
			}
			$a= $i-1; $TDcolor= $pages_array[$a];
				echo <<<HTML
						<td class='$TDcolor unselectable' style='width:$TDwitdh;'
						onclick="javascript: window.location.href='viewtext.php?game=$CMS_game&name=$CMS_file&page=$i$addEDITtoGET';">$i</td>
HTML;
			$per++;
		}
		echo "</table>";
	echo "</div>";

	if((isset($_GET['go']) AND $_GET['go']==="pending") OR (isset($_POST['editoract']) AND $_POST['editoract']==="yes")) { echo "<div id='transes001' style='display:block'>"; }
	else { echo "<div id='transes001' style='display:none'>"; }
		
	//---> Show all recorded translation for that text in that page
		$result_translations = mysql_query("SELECT * FROM $translations_table WHERE file_name = '".mysql_real_escape_string($CMS_file)."' and page = '".mysql_real_escape_string($CMS_page)."' ORDER BY id DESC");
		while($array_translations = mysql_fetch_array($result_translations)){
			$exploded= explode("\n", $array_translations['translation']);
			foreach ($exploded as $val) {
				$val_temp= explode("=>", $val);
				if(!isset($val_temp[1])) $val_temp[1]="";
				$userSEE[$val_temp[0]]['approved']=$val_temp[1];
			}
			unset($exploded);
			if ($array_translations['original']!=null){
				$exploded= explode("\n", $array_translations['original']);
				foreach ($exploded as $val) {
					$val_temp= explode("=>", $val);
					if(!isset($val_temp[1])) $val_temp[1]="";
					$userSEE[$val_temp[0]]['original']=$val_temp[1];
				}
				unset($exploded);
			}
			if($user_rights["ADD"]===1 AND $user_rights["APPROVE"]!==1 and $user_name != "guybrush"){
				$status = $array_translations['status'];
				if($status === 'Одобрен'){ $status_color = "GREEN"; } elseif($status === 'Неодобрен'){ $status_color = "RED"; } else { $status_color = "YELLOW"; }
				echo "<table><tr><td>";
				echo "<div class='apview-border border$status_color' id='".$array_translations['id']."'>";
				echo "<div class='forumheader'><a href=/user.php?id.".$array_translations['translator_id']." name=".$array_translations['id'].">".$array_translations['translator_name']."</a> <span class='smalltext' style='float: right;'>".$array_translations['time']."</span></div>";
				foreach($userSEE as $k=>$val) {
					$val['approved']= str_replace("<","&lt",$val['approved']);
					if ((trim($val['approved'])==trim($val['original']) OR !isset($val['original'])) AND ($val['approved']!=null)) {
						echo "<div class='forumheader3' style='padding:2px 4px;'>";
						echo "<span class='textBLUE'>$val[approved]</span>";
						echo "</div>";
					}
					elseif($val['approved']!=null) {
						$key = array_search("$k", $arr_echoid, true);
						echo "<div class='forumheader3' style='padding:2px 4px;'>";
						echo "<span class='textGREEN'>$val[approved]</span><br>";
						echo "<span class='textYELLOW'>$val[original]</span><br>";
						echo "<span class='textRED'>$arr_en[$key]</span><br>";
						echo "</div>";
					}
				}
				$status = $array_translations['status'];
				echo "<center class='forumheader text$status_color'>".$status."</center>";
				echo "</div>";
				echo "</td></tr></table>";
			}
			
	//---> Show translsation areas for admin + Approve/disapprove/delete translations
			if($user_rights["APPROVE"]===1 or $user_name == "guybrush"){
				$tran = ''; $pretran = '';
				$status = $array_translations['status'];
				$waiting_text = trim($array_translations['translation']);
					$waiting_rows = explode("\n", $waiting_text);
					foreach ($waiting_rows as $nextrow) {
						$exploded = explode("=>", $nextrow);
						$waiting_id[] = $exploded[0];
					}
					foreach ($waiting_id as $k=>$v) {
						$key = array_search($v, $arr_echoid, true);
						$pretran .= "<span class='textYELLOW'>".$arr_echoid[$key]."=</span>".$arr_content[$key]."<br>";
						$waiting_id_text[$k]['id']= $arr_echoid[$key];
						if($key!==false) {$waiting_id_text[$k]['en']= $arr_en[$key];}
						else $waiting_id_text[$k]['en']='Репликата вече е била означена на английски.';
						if (isset($arr_temp_green) AND in_array($arr_echoid[$key],$arr_temp_green)){
							$waiting_id_text[$k]['bg']= $arr_bg[$key]."<br>";
						} else $waiting_id_text[$k]['bg']='';
					}
				if($status == 'Одобрен'){ $status_color = "GREEN"; } elseif($status == 'Неодобрен'){ $status_color = "RED"; } else { $status_color = "YELLOW"; }
				echo "<table><tr><td>";
				echo "<div class='apview-border border$status_color' id='".$array_translations['id']."'>";
				echo "<div class='forumheader'><a href=/user.php?id.".$array_translations['translator_id'].">".$array_translations['translator_name']."</a> <span class='smalltext' style='float: right;'>".$array_translations['time']."</span></div>";
				if($status == 'В процес на проверка...') {
					echo "<form name='UFORM_$array_translations[id]' method='POST' action=''>";
					foreach ($waiting_rows as $rownum=>$rowbody) {
						$nextrow= explode("=>", $rowbody);
						$nextrow['1']= str_replace("&#xA","&amp;#xA",trim($nextrow['1']));
						echo "<textarea id='r_$array_translations[id]$rownum' name='r_$array_translations[id]$rownum' class='expand tbox borderGREY TBOX2' style='width:96%; margin:0px;' onChange='populateTextArea(\"UFORM_$array_translations[id]\",\"r_$array_translations[id]\",\"trans_$array_translations[id]\");clonecontent(\"r_{$array_translations['id']}{$rownum}\",\"r_{$array_translations['id']}{$rownum}_t\");' onKeyUp='populateTextArea(\"UFORM_$array_translations[id]\",\"r_$array_translations[id]\",\"trans_$array_translations[id]\");clonecontent(\"r_{$array_translations['id']}{$rownum}\",\"r_{$array_translations['id']}{$rownum}_t\");'>$nextrow[1]</textarea><div style='float:right; '><span class='button textRED' onClick='clearTextArea(\"r_$array_translations[id]$rownum\");populateTextArea(\"UFORM_$array_translations[id]\",\"r_$array_translations[id]\",\"trans_$array_translations[id]\");' style='vertical-align:middle;'>X</span></div>";
						echo "<div style='opacity:0.7; margin-top:-2px; margin-bottom:4px; margin-left:4px;' onmouseup=\"parseselection();\">".$waiting_id_text[$rownum]['bg'].$waiting_id_text[$rownum]['en'];
						if ($nextrow[0]!=null) $addarrow="=>";
						echo "<div style='float:right;'><textarea title='$nextrow[0]/".$waiting_id_text[$rownum]['id']."' type='text' id='r_$array_translations[id]$rownum-tag' name='r_$array_translations[id]$rownum-tag' class='expand16-1 tbox borderGREY TBOX2' style='margin:0px;width:75px;vertical-align:top;opacity:0.5;'>$nextrow[0]$addarrow</textarea></div>";
						echo "</div>";
					}
					echo "</form>";
				}
					unset ($waiting_rows, $exploded, $waiting_id);
				echo '<form action="" method="post">';
					if($status == 'Одобрен'){ 
						foreach($userSEE as $k=>$val) {
							if(!isset($val['approved'])) $val['approved']="";
							$val['approved']= trim(str_replace("<","&lt;",$val['approved']));
							$val['original']= trim(str_replace("<","&lt;",$val['original']));
							if ($val['approved']===$val['original'] OR $val['original']==null) {
								echo "<div class='forumheader3' style='padding:2px 4px;'>";
								echo "<span class='textBLUE'>$val[approved]</span>";
								echo "</div>";
							}
							elseif (empty($val['approved']) and empty($val['original'])) {}
							else {
								if (empty($val['approved']) and !empty($val['original'])) {$val['approved']="<изтрито>";}
								$key = array_search("$k", $arr_echoid, true);
								echo "<div class='forumheader3' style='padding:2px 4px;'>";
								echo "<span class='textGREEN'>$val[approved]</span><br>";
								echo "<span class='textYELLOW'>$val[original]</span><br>";
								echo "<span class='textRED'>$arr_en[$key]</span><br>";
								echo "</div>";
							}
						}
					} elseif($status == 'Неодобрен'){
						foreach($userSEE as $k=>$val) {
							$val['approved']= trim(str_replace("<","&lt;",$val['approved']));
							$val['original']= trim(str_replace("<","&lt;",$val['original']));
							$key = array_search("$k", $arr_echoid, true);
							if(!empty($val['original'])) {
								echo "<div class='forumheader3' style='padding:2px 4px;'>";
								echo "<span class='textYELLOW'>$val[original]</span><br>";
								echo "<span class='textRED'>$arr_en[$key]</span><br>";
								echo "</div>";
							}
						}
					}
					if ( isset($_GET['go']) AND $_GET['go']=="pending" ) {
						echo '<textarea name="trans_'.$array_translations['id'].'" id="trans_'.$array_translations['id'].'" class="expand tbox borderGREY TBOX2" style="width:99%;opacity:0.4;display:none;">'.$waiting_text.'</textarea>';
					}
					else {
						echo '<textarea name="trans_'.$array_translations['id'].'" id="trans_'.$array_translations['id'].'" class="expand tbox borderGREY TBOX2" style="width:99%;opacity:0.4;display:none;">'.$waiting_text.'</textarea>';
					}
/*				echo '<div class="forumheader"><a class="textGREY"><u>Настоящо състояние на репликите</u>: </a>(<a href="javascript:toggle(\'tip_'.$array_translations['id'].'\');">Покажи</a>)';
				echo '<div id="tip_'.$array_translations['id'].'" style="display: none; font-weight:normal;">';
				echo $pretran;
				echo '</div></div>'; */
				echo "<center class='forumheader' style='height:5px;'></center>";
				echo "<center class='forumheader3 text$status_color'>".$status."</center>";
				echo '<center class="forumheader" ><input type="hidden" name="editoract" value="yes">';
				if($status == 'Одобрен'){
					echo '<input name="approve_'.$array_translations['id'].'" type="submit" value="Одобри" style="text-decoration: line-through;" class="button" disabled>';
					echo '<input name="disapprove_'.$array_translations['id'].'" type="submit" value="Отхвърли" style="text-decoration: line-through;" class="button" disabled>';
				}
				elseif($status == 'Неодобрен'){
					echo '<input name="approve_'.$array_translations['id'].'" type="submit" value="Одобри" class="button">';
					echo '<input name="disapprove_'.$array_translations['id'].'" type="submit" value="Отхвърли" style="text-decoration: line-through;" class="button" disabled>';
				}
				else{
					echo '<a href="../../plugins/pm/pm.php?send.'.$array_translations['translator_id'].'" target="_blank" title="Изпрати лично съобщение. (Отваря нов таб.)"><img src="../../plugins/pm/images/pm.png" alt="Лични съобщения" class="button buttonBLACK" style="vertical-align:bottom;"></a>';
					echo '<input name="approve_'.$array_translations['id'].'" type="submit" value="Одобри" class="button buttonGREEN">';
					echo '<input name="change_'.$array_translations['id'].'" type="submit" value="Редактирай" class="button buttonYELLOW">';
					echo '<input name="disapprove_'.$array_translations['id'].'" type="submit" value="Отхвърли" class="button buttonRED">';
				}
				echo '<input name="delete_'.$array_translations['id'].'" type="submit" value="Изтрий" class="button buttonBLACK" /></center>';
				
				echo "<input type='hidden' name='sbmtchck' value='true'>";
				
				echo '</form>';
				echo "</div>";
				echo "</td>";
				echo "</tr>";
				echo "</table>";
			}
			unset($userSEE);
		}
	echo "</div>";

	if(isset($_POST['comsubmit'])) { echo "<div id='comments001' style='display:block'>"; }
	else { echo "<div id='comments001' style='display:none'>"; }
				if (isset($_POST['comment'])) {
					$posteded = strtoupper($_POST['comment']); 
					$posteded = strip_tags($posteded); 
					$posteded = trim ($posteded);
				}
				if(isset($_POST['comsubmit']) AND $posteded != '') {
					mysql_query("INSERT INTO cms_notes (`note`, `game`, `user_id`, `user_name`) VALUES ('".mysql_real_escape_string($posteded)."', '".mysql_real_escape_string($CMS_game)."', '$user_id', '$user_name')");
				}			

				$temp=0;
				$notes= mysql_query("SELECT * FROM cms_notes WHERE game = '".mysql_real_escape_string($CMS_game)."' ORDER by time DESC");
				while($note = mysql_fetch_array( $notes )) {
					$arr_notes[$temp]['note']= $note['note'];
					$arr_notes[$temp]['status']= $note['status'];
					$arr_notes[$temp]['time']= $note['time'];
					$arr_notes[$temp]['user']= $note['user_name'];
					$temp++;
				}
				
				if ($temp == 0) { echo "<center><span class='textRED' style='font-size:150%; vertical-align:bottom;'>✆</span> <span class='textBLUE' style='font-weight:bold;'><u>Все още няма добавени бележки.</u></span></center>"; }
				echo "<div class='textWHITE'>";
				$temp=1;
				if(isset($arr_notes)) {
					foreach ($arr_notes as $key => $note) {
						  $note['time']= months_inBG(date("j F : H:i", strtotime($note['time'])));
						  if ($temp%2===0) { $class= "cmntRow1"; $class2= "cmntUser1"; } else { $class= "cmntRow2"; $class2= "cmntUser2"; }
						  echo "<div class='forumheader3'><span class='$class2'>".$note['user']."</span> <span class='cmntDate'>".$note['time']."</span><br>";
						  echo "<div style='float:left;' style='font-size:14px;'> <span class='unselectable' style='color:lightgrey'>⌨</span> ".$note['note']."</div><br>";
						  echo "</div>";
						  $temp++;
					}
				}
				echo "</div>";
				echo "<div class='forumheader3'>	
						<form method='post' action='viewtext.php?game=$CMS_game&name=$CMS_file&page=$CMS_page$addEDITtoGET#menu2'>
						<center style='padding-top:5px;'><textarea name='comment' cols='50' id='comment' class='expand tbox borderGREY TBOX2'>Вашият коментар...</textarea>
						<br><input type='submit' value='Изпрати' name='comsubmit' class='button'></center>
						</form>
					  </div>";
	echo "</div>";

	$translationButtons= "";
	if($user_rights["APPROVE"]===1){
		$pendings= CMS_pendingTranslationsLoad("for game");
		if (!isset($_GET['pendingID'])) {
			$filestart= array_search($CMS_file, $pendings);
			foreach ($pendings as $index => $pending) {
				if ($pending['page']<$CMS_page AND $pending['file_name']==$CMS_file) {$prev_key= $index;}
				elseif ($pending['page']>=$CMS_page AND $pending['file_name']==$CMS_file) {$next_key= $index; break;}
				else {
						$temp= $filestart-1;
						if (isset($pendings[$temp])) { $prev_key= $temp; }
						$temp= $filestart+1;
						if (isset($pendings[$temp])) { $next_key= $temp; }
				}
			}
		}
		else {
			$present= $_GET['pendingID'];
			$temp= $present-1;
			if (isset($pendings[$temp])) { $prev_key= $temp; }
			$temp= $present+1;
			if (isset($pendings[$temp])) { $next_key= $temp; }
		}
		if (isset($prev_key)) {
			$tmp_name= $pendings[$prev_key]['file_name']; $tmp_page= $pendings[$prev_key]['page']; $tmp_id= $pendings[$prev_key]['id'];
			$prev="viewtext.php?game=$CMS_game&name=$tmp_name&page=$tmp_page&pendingID=$prev_key&go=pending$addEDITtoGET#$tmp_id";
		}
		if (isset($next_key)) {
			$tmp_name= $pendings[$next_key]['file_name']; $tmp_page= $pendings[$next_key]['page']; $tmp_id= $pendings[$next_key]['id'];
			$next="viewtext.php?game=$CMS_game&name=$tmp_name&page=$tmp_page&pendingID=$next_key&go=pending$addEDITtoGET#$tmp_id";
		}
		if (isset($prev)) {$translationButtons.="<a href='$prev' style='vertical-align:middle;' id='prev-trans'>◄</a>";}
		if($pendings['count']==0){$tclass='textBLACK';} else $tclass='textDBLUE';
		$translationButtons.="<span class='$tclass' style='vertical-align:middle; font-weight:bold;'>".$pendings['count']."</span>";
		if (isset($next)) {$translationButtons.="<a href='$next' style='vertical-align:middle;' id='next-trans'>►</a>";}
		//$translationButtons= "<button title='Всички преводи' class='cmsBottomButton' onClick=window.open('apall.php?game=$CMS_game')><img src='icons/bottom-approve.png' HEIGHT='14px' WIDTH='14px'></button>".$translationButtons;
	}

	$youtubesrc= urlencode($gamename);	
	echo <<<HTML
				<center class='cmsBottomBar forumheader'>
						<form name="redirectSearch" method="post" action="redirect.php" target="_blank" style="display: inline;">
						<input type="text" name="keyword" id="keyword" class="cmsTextarea2 borderGREY" style="vertical-align:bottom;"/>
						<button title="Потърси в речник" type="submit" name="direction_dir-bg" id="srch-dict" class="cmsBottomButton" value="sent"><img src="icons/bottom-dirbg.png" HEIGHT='14px' WIDTH='14px'></button><button title="Потърси в Urban Dictionary" type="submit" name="direction_urbandict" id="srch-urban" class="cmsBottomButton" value="sent"><img src="icons/bottom-urbandict.png" HEIGHT='14px' WIDTH='14px'></button><button title="Потърси с Google" type="submit" name="direction_google" id="srch-ggle" class="cmsBottomButton" value="sent"><img src="icons/bottom-google.png" HEIGHT='14px' WIDTH='14px'></button><button title="Потърси в Уикипедия" type="submit" name="direction_wiki" id="srch-wiki" class="cmsBottomButton" value="sent"><img src="icons/bottom-wikipedia.png" HEIGHT='14px' WIDTH='14px'></button><button type="submit" title="Преведи с Google Translate" name="direction_gtranslate" id="srch-gtr" class="cmsBottomButton" value="sent"><img src="icons/bottom-gtranslate.png" HEIGHT='14px' WIDTH='14px'></button><button type="submit" title="Английски тълковен речник" name="direction_thefreedict" id="srch-tfd" class="cmsBottomButton" value="sent"><img src="icons/bottom-thefreedict.png" HEIGHT='14px' WIDTH='14px'></button><button type="submit" title="Речник на българския език" name="direction_chitankadict" id="srch-chi" class="cmsBottomButton" value="sent"><img src="icons/bottom-chitankadict.png" HEIGHT='14px' WIDTH='14px'></button>
						</form>
						<span class='unselectable textBLACK'>||</span>
						$translationButtons
						<span class='unselectable textBLACK'>|| </span>
						<button title='YouTube помагало' class='cmsBottomButton' onClick=window.open('http://www.youtube.com/results?search_query=$youtubesrc+walkthrough')><img src='icons/bottom-youtube.bmp' HEIGHT='14px'></button>
					</center>
HTML;
	if($user_rights["APPROVE"]===1){
		echo "		<div class='cmsRightBar' style='margin-bottom: 150px;'>";
		for($ictrl=1;$ictrl<=9;$ictrl++){
			if (isset($_COOKIE['playon-ctrls'][$ictrl])) { $ctrl_value= $_COOKIE['playon-ctrls'][$ictrl]; } else $ctrl_value= "";
			echo "		<button disabled='disabled' id='CTRL$ictrl' class='button' style='cursor:help !important;' title='Ctrl+$ictrl\nНатискането на комбинцията, докато попълвате превод, въвежда съдържанието на полето след това квадратче в полето, където пишете.'>$ictrl</button>
						<input type='text' name='CTRL$ictrl-text' id='CTRL$ictrl-text' class='cmsTextarea2' style='width:60px;' value='$ctrl_value'/>
						<br>";
		} echo "	<button id='savectrls' class='button'>Запази</button>
					<div id='savectrls-message'></div>
					</div>";	
	}
	if($user_rights["APPROVE"]===1){
		echo <<<HTML
					<div class='cmsRightBar' style='margin-bottom: 50px;'>
					<button disabled='disabled' class='button' style='cursor:help !important;' title='Дума на английски\nЗадължителна, за да се започне изпращането.'>EN</button>
					<input type='text' id='wordEN' name='wordEN' class='cmsTextarea2' style='width:50px;'/>
					<button disabled='disabled' class='button' style='cursor:help !important;' title='Превод на български\nЗадължителен, за да се започне изпращането.'>BG</button>
					<input type='text' id='wordBG' name='wordBG' class='cmsTextarea2' style='width:50px;'/>
					<button id='savedict' class='button'>Въведи</button>
					<div id='savedict-message'></div>
					</div>
HTML;
	}

	}else{
		echo "<center class='textRED'>Само регистрирани потребители могат да се включат в превода</center><div>";
	}
	echo "</div></div><div class='forumheader2'></div>";
	require_once("viewtext-java.php");
}
ramka("close");
$text= null;
require_once(FOOTERF);

}else {
	echo "<div class='forumheader'>Не е уточнена игра, която да бъде показана, играта е преведена, или нямате достъп до нея. Извиняваме се за неудобството.</div>";
	ramka("close");
	require_once(FOOTERF);
}
?>